package com.woniu.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniu.entity.CheckinSummary;
import com.woniu.entity.Checkinfo;
import com.woniu.entity.CheckinfoDetails;
import com.woniu.service.CheckinfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author 杨光 微信号:tolryg
 * @time 15:53
 */
@RestController
@CrossOrigin
public class CheckinfoController {

    @Autowired
    private CheckinfoService checkinfoService;

    @RequestMapping("findAllStudentsCheckInfo")
    public List<Checkinfo> findAllStudentsCheckInfo(){
        return checkinfoService.findAllStudentsCheckInfo();
    }

    @RequestMapping("saveStudentsCheckInfo")
    public void saveStudentsCheckInfo(@RequestBody  List<Checkinfo> list){
        checkinfoService.saveStudentsCheckInfo(list);
    }

    @RequestMapping("findAllStudentsCheckInfoDetails")
    public PageInfo<CheckinfoDetails> findAllStudentsCheckInfoDetails(
            String stuClass,
            String stuName,
            Integer month,
            Integer pageNum
    ){
        System.out.println("stuClass = " + stuClass);
        System.out.println("stuName = " + stuName);
        System.out.println("month = " + month);
        System.out.println("pageNum = " + pageNum);


        //pageNum 查看第几页的数据，第二个参数是每一页显示几条记录
        PageHelper.startPage(pageNum,3);

        List<CheckinfoDetails> list =  checkinfoService
                .findAllStudentsCheckInfoDetails(stuClass, stuName, month, pageNum);

        PageInfo<CheckinfoDetails> pageInfo = new PageInfo<>(list);

        return pageInfo;

    }


    @RequestMapping("selectCheckinfoSummary")
    public List<CheckinSummary> selectCheckinfoSummary(String stuClass){
        return checkinfoService.selectCheckinfoSummary(stuClass);
    }

}
